//
//  NotView.m
//  项目三
//
//  Created by rimi1 on 2016/12/13.
//  Copyright © 2016年 Wangxingqian. All rights reserved.
//

#import "NotView.h"
#import "ElasticShapeLayer.h"

static NSInteger spacing_ = 20;

@interface NotView ()

@property (nonatomic, strong) ElasticShapeLayer *shapeLayer;

@end

@implementation NotView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.imageView];
        [self addSubview:self.refresh];
        [self addSubview:self.title];
    }
    return self;
}

- (void)respondsToButton:(UIButton *)sender {
    [self.shapeLayer showAnimation];
    if (self.tapRefresh) {
        self.tapRefresh();
    }
}

#pragma mark - get

- (UIImageView *)imageView {
    
    if (!_imageView) {
        
        CGFloat height = WXQAdaptionHeight(self.bounds.size.height/3);
        CGFloat width = height * 9/10;
        _imageView = [[UIImageView alloc] initWithFrame:CGRectMake((kWIDTH - width)/2, self.bounds.size.height/2 - height * 2/3, width, height)];
        _imageView.image = [UIImage imageNamed:@"Not.jpg"];
        
    }
    return _imageView;
}

- (UIButton *)refresh {
    
    if (!_refresh) {
        
        CGFloat width = WXQAdaptionWidth(70);
        CGFloat height = 45;
        _refresh = [[UIButton alloc] initWithFrame:CGRectMake((kWIDTH - width)/2, CGRectGetMinY(self.imageView.frame) - spacing_/2 - height, width, height)];
        [_refresh setTitle:@"刷  新" forState:UIControlStateNormal];
        [_refresh addTarget:self action:@selector(respondsToButton:) forControlEvents:UIControlEventTouchUpInside];
        
        self.shapeLayer = [[ElasticShapeLayer layer] initWithSize:_refresh.bounds.size elastic:WXQAdaptionHeight(20) elasticCount:9 circular:5 fillColor:[UIColor orangeColor].CGColor];
        [_refresh.layer addSublayer:self.shapeLayer];
        
    }
    return _refresh;
}

- (UILabel *)title {
    
    if (!_title) {
        
        CGFloat height = WXQAdaptionHeight(18);
        _title = [[UILabel alloc] initWithFrame:CGRectMake(spacing_, CGRectGetMaxY(self.imageView.frame) + spacing_/2, kWIDTH - spacing_ * 2, height)];
        _title.font = [UIFont systemFontOfSize:height];
        _title.textAlignment = NSTextAlignmentCenter;
        
    }
    return _title;
}

@end









